<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        /*  输入两个数求两个数的最大公约数
	    - 先取出两个数中最小的数
        - 最小的数不断递减，取出能同时被两个数整除的数，并退出循环 */
        function yueNum(n1, n2) {
            var min = n1 < n2 ? n1 : n2;
            for (var i = min; i >= 1; i--) {
                if (n1 % i == 0 && n2 % i == 0) { 
                    return i;
                }
            }
        }

        var r = yueNum(58,56);
        console.log(r);
        

    </script>
</body>

</html>